The Age Calculator
Forgot how old someone is? Calculate it!
Store the current year in a variable.
Store their birth year in a variable.
Calculate their 2 possible ages based on the stored values.
Output them to the screen like so: “They are either NN or NN”, substituting the values.
Input your birthday year
The Fortune Teller
Why pay a fortune teller when you can just program your fortune yourself?
Store the following into variables:
number of children
partner’s name
geographic location
job title
Output your fortune to the screen like so: “You will be a X in Y, and married to Z with N kids.”
Using Math functions
JavaScript has a built-in tool that can generate a random number between 0 and 1. This tool is called
a method. We’ll talk about methods more later in the class. For now, know if you type Math.random(),
you’ll get a random number between 0 and 1.
Using this tool, update your fahrenheit to celsius temperature conversion program to do the following:
Instead of inputing a value for the Fahrenheit temperature, use Math.random() to generate a random
temperature between 0 and 100
Have to program output: “It is NN°F today. That’s NN°C.”
The Temperature Converter
Let’s make a program to convert celsius temperatures to fahrenheit and vice versa, so we can
complain about the weather with our friends overseas.
Reminder: To convert celsius to fahrenheit, multiply by 9, then divide by 5, then add 32.
To convert fahrenheit to celsius, deduct 32, then multiply by 5, then divide by 9.
Unicode Characters: To print the degrees symbol in JavaScript, we need to use the write
\u00B0 to represent the unicode character for the degrees symbol.
Store a celsius temperature into a variable.
Convert it to fahrenheit and output “NN°C is NN°F”.
Now store a fahrenheit temperature into a variable.
Convert it to celsius and output “NN°F is NN°C.”
Input temperature, °C
or
Input temperature, °F